package com.xhu.water_supply.web.controller;

import com.xhu.water_supply.entity.Worker;
import com.xhu.water_supply.service.WorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/worker")
public class WorkerController {

    @Autowired
    private WorkerService workerService;

    @PostMapping("/add")
    public Boolean add(Worker worker) {
        return workerService.add(worker);
    }

    @GetMapping("/del/{id}")
    public Boolean del(@PathVariable int id) {
        return workerService.del(id);
    }

    @PostMapping("/edit")
    public Boolean edit(Worker worker) {
        return workerService.edit(worker);
    }

    @GetMapping("/findAll")
    public List<Worker> findAll() {
        return workerService.findAll();
    }

    @GetMapping("/findOne/{id}")
    public Worker findOne(@PathVariable int id) {
        return workerService.findOne(id);
    }

    @GetMapping("/findName/{name}")
    public List<Worker> findName(@PathVariable String name) {
        return workerService.findName(name);
    }


/*    @PostMapping("/add")
    public void add(Worker worker, HttpServletRequest request) throws IOException {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile multipartFile = multipartRequest.getFile("file"); // 通过参数名获取指定文件
        worker.setPicture(multipartFile.getName());
        workerService.add(worker);
        pictureUploadService.save(multipartFile);*/


    }

